<template>
  <div class="no-auth-container">
    <div class="no-auth-content">
      <div class="error-code">401</div>
      <div class="error-title">权限不足</div>
      <div class="error-description">
        抱歉，您没有访问该页面的权限，请联系管理员或尝试其他操作
      </div>
      <div class="error-actions">
        <el-button type="primary" @click="goHome">返回首页</el-button>
        <el-button @click="goBack">返回上一页</el-button>
        <el-button @click="reLogin" v-if="showReLogin">重新登录</el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()
const showReLogin = ref(true)

const goHome = () => {
  router.push('/')
}

const goBack = () => {
  router.go(-1)
}

const reLogin = () => {
  // 清除本地存储的认证信息
  sessionStorage.clear()
  localStorage.removeItem('token')
  router.push('/login')
}
</script>

<style scoped>
.no-auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f7fa;
}

.no-auth-content {
  text-align: center;
  padding: 40px;
  border-radius: 8px;
  background: white;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.error-code {
  font-size: 72px;
  font-weight: bold;
  color: #f56c6c;
  margin-bottom: 20px;
}

.error-title {
  font-size: 24px;
  color: #333;
  margin-bottom: 15px;
}

.error-description {
  font-size: 16px;
  color: #666;
  margin-bottom: 30px;
}

.error-actions .el-button {
  margin: 0 10px;
}
</style>
